<?php
// Example for a simple client

// Load the settings from the central config file
//include_once('config.php');
// Load the CAS lib
### Inicializa Sesion UC
include_once('../CAS-UC/CAS.php');

// Uncomment to enable debugging
phpCAS::setDebug();

// Inicializa librería phpCAS
phpCAS::client(CAS_VERSION_2_0, 'sso.uc.cl', 443, '/cas');
phpCAS::setNoCasServerValidation();
//exije estar Logueado uc
phpCAS::forceAuthentication();


#Una vez logueado guarda una variable de sesion boolean que indica si está logueado o no 
if (isset($_SESSION['loggedInLocally'])) {
   $_SESSION['username'] = phpCAS::getUser();  //this stores their network user id
}
else
    {
 
    phpCAS::forceAuthentication();
    $_SESSION['loggedInLocally'] = true;  //set a local variable telling the program we are logged in
    }

    ###Para hacer logout.
    if (isset($_REQUEST['logout'])) {
   $_SESSION['loggedInLocally'] = false;
   unset($_SESSION['username']);
phpCAS::logout();   
}
?>


<html>
  <head>
    <title>phpCAS simple client</title>
  </head>
  <body>
    <h1>Successfull Authentication!</h1>
    <?php/// include 'script_info.php' ?>
    <p>El login UC del usuario es: <b><?php echo phpCAS::getUser(); ?></b>.</p>
    <p>phpCAS version is <b><?php echo phpCAS::getVersion(); ?></b>.</p>
    <p><a href="?logout=">Logout</a></p>
  </body>
</html>
